package com.woniuxy.controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.Bidding;
import com.woniuxy.entity.Collect;
import com.woniuxy.entity.Sign;
import com.woniuxy.service.BiddingService;
import com.woniuxy.utils.ResultUtil;

@RequestMapping("/bidding")
@Controller
public class BiddingController {
     @Autowired
	 private BiddingService biddingService;
     
     @ResponseBody
     @RequestMapping("/addSigner") //添加报名人数
     public ResultUtil<Object> addsiginer(int p_id,int u_id,int br_id) {
    	 Sign sign=new Sign().setBr_id(br_id).setP_id(p_id).setU_id(u_id).setTime(new Date());
    	 ResultUtil<Object> resultUtil =new ResultUtil<>();
           boolean addsiginer = biddingService.addsiginer(sign);
           if(addsiginer) {
        	   resultUtil.setMessage(ResultUtil.SUCCESS);
        	   resultUtil.setStatus(ResultUtil.SUCCESS);
        	   return resultUtil;
           }
           resultUtil.setMessage(ResultUtil.ERROR);
    	   resultUtil.setStatus(ResultUtil.ERROR);
    	   return resultUtil;
     }
     
     @ResponseBody
     @RequestMapping("/findSignerNums") //查询报名人数
     public ResultUtil<Object> findSigner() {
    	 
    	 
    	 
		return null;
    	 
     }
     
  
     
     
     @ResponseBody
     @RequestMapping("/addBidding")
     public ResultUtil<Object> addBid(int br_id,int u_id,BigDecimal price) {//添加竞价记录
    	 Bidding bidding=new Bidding().setAlias("lisi").setTime(new Date()).setU_id(u_id)
    			 .setPrice(price).setBr_id(br_id);
    	 int addBidding = biddingService.addBidding(bidding);
    	 ResultUtil<Object> resultUtil =new ResultUtil<>();
    	 if(addBidding==1) {
    		 
       	  resultUtil.setMessage(ResultUtil.SUCCESS);
       	  resultUtil.setStatus(ResultUtil.SUCCESS);
       	    return resultUtil;
    	 }
    	 resultUtil.setMessage(ResultUtil.ERROR);
      	  resultUtil.setStatus(ResultUtil.ERROR);  
      	 return resultUtil;
		
    	 }
   
     @ResponseBody
     @RequestMapping("/addCollection")
 	public ResultUtil<Object> addCollection(int u_id,int p_id) {//添加收藏
    	  Collect collect=new Collect().setP_id(p_id).setRemind_way(1).setU_id(u_id)
    			  .setTime(new Date());
    	  
    	  
 	             Boolean addCollection = biddingService.addCollection(collect);
 	            ResultUtil<Object> resultUtil=new ResultUtil<>();
 	             if(addCollection) {
 	 	              resultUtil.setMessage(ResultUtil.SUCCESS);
 	 	              return resultUtil;
 	             }
 	            resultUtil.setMessage(ResultUtil.ERROR);
	              return resultUtil;
            
 	}
     @ResponseBody
     @RequestMapping("/collector_nums")
 	public int countCollecters(int p_id) { //查询收藏人数
 		int countCollecters = biddingService.allCollectors(p_id);
 		System.out.println("收藏人数"+countCollecters);
		return countCollecters;
 		
 		
 	}
     

     
     @ResponseBody
     @RequestMapping("/findSignerAndReminder")
  	public ResultUtil<int[]>findSingerAndReminder(int p_id) {//查询预约人数和收藏人数
  		System.out.println("findSignerAndReminder");
  		  int[] singerAndReminder = biddingService.singerAndReminder(p_id);
  		 ResultUtil<int[]> resultUtil =new ResultUtil<>();
  		 resultUtil.setData(singerAndReminder);
  		 resultUtil.setStatus(ResultUtil.SUCCESS);
 		return resultUtil;	
  	}
  	
  	  
  	 @ResponseBody
     @RequestMapping("/findRecords")
  	public ResultUtil< PageInfo<Bidding>>findRecords(int p_id,int pageNum) {//分页查询d竞价记录
  		 System.err.println(pageNum);
  		 
  		 PageInfo<Bidding> findBiddingRecords = biddingService.findBiddingRecords(p_id,pageNum,2);
  		 ResultUtil< PageInfo<Bidding>> resultUtil =new ResultUtil<>();
  		 resultUtil.setData(findBiddingRecords);
  		 resultUtil.setStatus(ResultUtil.SUCCESS);
  		 
 		return resultUtil;	
  	}
  	 
  	 
  	 @ResponseBody
     @RequestMapping("/findAllRecords")
  	public ResultUtil< List<Bidding>>findRecords(int p_id) {//查询所有竞价记录
  		  List<Bidding> findBiddingRecords = biddingService.findAllRecords(p_id);
  		 ResultUtil<List<Bidding>> resultUtil =new ResultUtil<>();
  		 resultUtil.setData(findBiddingRecords);
  		 resultUtil.setStatus(ResultUtil.SUCCESS);
  		System.err.println(resultUtil);
 		return resultUtil;	
  	}
  	 
  	 
  	 @ResponseBody
     @RequestMapping("/addVistor")
  	 //增加围观人数      --------------已经实现
  	 public ResultUtil<Object> addVistor(int p_id,int u_id) {
  		            Boolean addVistor = biddingService.addVistor(p_id);
  		            ResultUtil<Object> resultUtil=new ResultUtil<>();
  		            if(addVistor) {
  		            	resultUtil.setStatus(ResultUtil.SUCCESS);
  		            	return resultUtil;
  		            }
  		          resultUtil.setStatus(ResultUtil.ERROR);
  		 
		return resultUtil;
  		 
  	 }
  	
     
     
     
     
	
}
